package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;

import com.ruoyi.system.domain.SysAccountInfo;
import com.ruoyi.system.domain.vo.SaleTypeResultDto;
import com.ruoyi.system.domain.vo.SysConsumerDto;
import com.ruoyi.system.domain.vo.TemplateSaveDto;
import jakarta.annotation.security.PermitAll;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysConsumer;
import com.ruoyi.system.service.ISysConsumerService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/consumer")
public class SysConsumerController extends BaseController
{
    @Autowired
    private ISysConsumerService sysConsumerService;

    /**
     * 查询用户信息列表
     */
    @RequiresPermissions("system:consumer:list")
    @GetMapping("/list")
    public TableDataInfo list(SysConsumer sysConsumer)
    {
        startPage();
        List<SysConsumer> list = sysConsumerService.selectSysConsumerList(sysConsumer);
        return getDataTable(list);
    }



    /**
     * 获取用户信息详细信息
     */
    @RequiresPermissions("system:consumer:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(sysConsumerService.selectSysConsumerByUserId(userId));
    }

    /**
     * 新增用户信息
     */
    @RequiresPermissions("system:consumer:add")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysConsumer sysConsumer)
    {
        return toAjax(sysConsumerService.insertSysConsumer(sysConsumer));
    }

    /**
     * 修改用户信息
     */
    @RequiresPermissions("system:consumer:edit")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysConsumer sysConsumer)
    {
        return toAjax(sysConsumerService.updateSysConsumer(sysConsumer));
    }



    /**
     * 详情
     */
    @PermitAll
    @GetMapping(value = "/getDetail")
    public SysConsumerDto getDetail(@RequestParam Long consumerId, @RequestParam String userType){
        SysConsumerDto dto = sysConsumerService.getDetailInfo(consumerId,userType);
        return dto;

    }


    /**
     * 操作 冻结，停用，解冻，启用
     */
    @PermitAll
    @Log(title = "用户列表操作", businessType = BusinessType.OTHER)
    @PostMapping("/operate")
    public AjaxResult operate(@RequestParam Long consumerId, @RequestParam String usageStatus)
    {
        return toAjax(sysConsumerService.operate(consumerId,usageStatus));
    }


    /**
     * 销售方式选择信息保存 toB 1 toC 2 toB、toC 3
     *
     */
    @PermitAll
    @PostMapping("/saleTypeSave")
    public AjaxResult saleTypeSave(@RequestBody SaleTypeResultDto saleTypeDtoList)
    {
        return toAjax(sysConsumerService.saleTypeSave(saleTypeDtoList));
    }

    /**
     * 模板选择信息保存  saleType 1 toB    2 toC
     *
     */
    @PermitAll
    @PostMapping("/templateSave")
    public AjaxResult templateSave(@RequestBody TemplateSaveDto templateSaveDto)
    {
        return toAjax(sysConsumerService.templateSave(templateSaveDto));
    }

}
